package leetcode_2301_2400;

public class LeeCode_2337 {
    public static void main(String[] args) {
        System.out.println(canChange("_L__R__R_", "L______RR"));
        System.out.println(canChange("_R", "R_"));
    }
    private static boolean canChange(String start, String target) {
        int n = start.length();
        int i = 0, j = 0;
        while (i < n){
            while (i < n && start.charAt(i) == '_'){
                i++;
            }
            while (j < n && target.charAt(j) == '_'){
                j++;
            }
            if (i < n && j < n && start.charAt(i) != target.charAt(j)){
                return false;
            }
            if (i >= n)
                continue;
            if (j < n && ((start.charAt(i) == 'L' && i >= j) || (start.charAt(i) == 'R' && i <= j))){
                i++;
                j++;
            }else {
                return false;
            }
        }
        while (j < n){
            if (target.charAt(j) != '_')
                return false;
            j++;
        }
        return true;
    }
}
